<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <script type="text/javascript" src="../../script/api.js"></script>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <style>
        html {
            font-size: 33%;
            height: 100%;
            width: 100%;
            display: table;
        }

        body {
            display: table-cell;
            width: 100%;
            height: 100%;
        }
        ul{
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        .all{
            height: 100%;
            width: 100%;
        }
        .top{
            position: relative;
            background-color: #f7911b;
            height:7rem;
            width: 100%;
            text-align: center;
        }
        .back{
            font-size: 6rem;
            color: white;
            left: 2rem;
            line-height: 6.5rem;
            position: absolute;
        }
        .title{
            font-size: 3.5rem;
            color: white;
            line-height: 7rem;
           margin-left: -3rem;
        }
        .main{
            position: absolute;
            height: 92.32%;
            width: 100%;
            background-color: #f6f6f6;
            overflow: auto;
        }
        .content{
        position: absolute;
            width: 100%;
            height: 100%;
            background-color: white;
        }
        .content img{
            width: 18rem;
            height: 18rem;
            display: block;
            margin: auto;
            margin-top: 8rem;
        }
        .now_ed{
            display: block;
            text-align: center;
            margin: auto;
            font-size: 2.5rem;
            margin-top: 3rem;
            color: #666666;
        }
        .new_ed{
            display: block;
            text-align: center;
            margin: auto;
            font-size: 2.5rem;
            margin-top: 18rem;
            color: #666666;
        }
        .upd_btn{
            background-color: red;
            width: 23rem;
            height: 6rem;
            color: white;
            border: 0;
            border-radius: 1rem;
            font-size: 2.22rem;
            margin: auto;
            margin-top: 3rem;
            display: block;
        }
        .disupd_btn{
                    background-color: #999999;
                    width: 23rem;
                    height: 6rem;
                    color: white;
                    border: 0;
                    border-radius: 1rem;
                    font-size: 2.22rem;
                    margin: auto;
                    margin-top: 3rem;
                    display: block;
                }


    </style>
</head>
<body>
<div class="all">
    <div class="top">
        <span class="aui-iconfont aui-icon-left" style="font-size: 4rem;line-height: 7rem;float: left;margin-left: 0.7rem;" onclick="api.closeWin()"></span>
        <span class="title">版本更新</span>
    </div>
    <div class="main">
        <div class="content" id="main">
            <!-- <img src="../../image/applogo.png">
            <span class="now_ed">当前版本<span>19.1.0</span></span>
            <span class="new_ed">最新版本<span>19.2.0</span></span>
            <button class="upd_btn" onclick=" checkUpdate()">更新</button> -->
        </div>
    </div>
</div>
</body>
<script>
    $(function() {
        var now = $('.now_ed').children('span').text();
        var upd = $('.new_ed').children('span').text();
        if (now==upd)
            {
                $('.upd_btn').attr('disabled','disabled');
                $('.upd_btn').attr('class','disupd_btn');
            }
    })

    apiready = function(){
        
      
       
            var mam = api.require('mam');
            var appVersion = api.appVersion;
            mam.checkUpdate(function(ret, err) {
                if (ret) {
                    var result = ret.result;
                    if (result.update == true && result.closed == false) {

                        // $api.byId('main').innerHTML =''
                        // var str = '新版本型号:' + result.version + ';更新提示语:' + result.updateTip + ';下载地址:' + result.source + ';发布时间:' + result.time;
                        $api.byId('main').innerHTML =' <img src="../../image/applogo.png">'+
            '<span class="now_ed">当前版本<span>'+appVersion+'</span></span>'+
            '<span class="new_ed">新版本型号:<span>' + result.version +'</span></span>'+
            ' <button class="upd_btn" onclick="gengxin()">更新</button>'

                        window.gengxin = function() {
                            api.confirm({
                            title : '有新的版本,是否下载并安装 ',
                            msg : str,
                            buttons : ['确定', '取消']
                        }, function(ret, err) {
                            if (ret.buttonIndex == 1) {
                                if (api.systemType == "android") {
                                    api.download({
                                        url : result.source,
                                        report : true
                                    }, function(ret, err) {
                                        if (ret && 0 == ret.state) {/* 下载进度 */
                                            api.toast({
                                                msg : "正在下载应用" + ret.percent + "%",
                                                duration : 2000
                                            });
                                        }
                                        if (ret && 1 == ret.state) {/* 下载完成 */
                                            var savePath = ret.savePath;
                                            api.installApp({
                                                appUri : savePath
                                            });
                                        }
                                    });
                                }
                                if (api.systemType == "ios") {
                                    api.installApp({
                                        appUri : result.source
                                    });
                                }
                            }
                        });
                        }
                        
                    } else {
                        // api.alert({
                        //     msg : "暂无更新"
                        // });

                        $api.byId('main').innerHTML =' <img src="../../image/applogo.png">'+
            '<span class="now_ed">当前版本<span>'+appVersion+'</span></span>'+
            '<span class="new_ed">暂无版本</span>'+
            ' <button class="upd_btn" >暂无</button>'
                    }
                } else {
                    api.alert({
                        msg : err.msg
                    });
                }
            });
        }
    
        
</script>
</html>